import requests
import subprocess
from functools import partial
import json
subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')
import execjs
import requests
import time
with open('调试.js', 'r', encoding='utf-8') as f:
    js = f.read()

js_com = execjs.compile(js)
import requests


headers = {
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ru;q=0.7',
    'cache-control': 'no-cache',
    # 'cookie': '_ga=GA1.1.1524154300.1720080497; ssxmod_itna=muD=0KDKAKiILxlfxCorpG7DynboDCb3Kt3Fb+FB+RDBdko4iNDnD8x7YDv+Ude=orqWdFB4PGOe4eFjK0KF0PhHIC1YuRQrDCPGnDBFb=5+DYA1Dt4DTD34DYDixibhxi5GRD0KDFGkvzMo5Dbxi30xiaDGeDexv8DY5DhxDCclPDwx0C01iboQH4DGy5sQDD4pu4Y9BHrIHIypWwOmxCD7yIDlc4MK8plSk4VcY698Adfx0kdq0OMp5GhpoPuPYsKt2W=WieEnDYfDTbOD+xommorWiqkBGSqj0KfAc5INWdTlZyDDaKoGdDWP4D==; ssxmod_itna2=muD=0KDKAKiILxlfxCorpG7DynboDCb3Kt3Fb+FBD8w1Oq7KD/3DxxFoM7YqNUDE4ubGqid/96kI27B3FYqY+51z+OwvB4+PyKCqb0Qoo12AOjDUKq/htkKsDM8Qd3IfaqxZKsqjtebLEqYdQFkPlaQOGak5C0NxIrFzB97q4RKH4cWK6GF2nDTsE9OwpWkuOnHOWmE4F5tGeATYZgLOcm+nmrkK1GTuocr97Er/9i0nmkKxNnHco5=cKvpPZLce5oaEp=9u11QgD/rMCd8gBOxPcQ8=sWFX/EGf4o9yhWUo8CL0u092bHPgru05=EWR7KO2aK+8G2i=7z2YaQ+8iRWKWOPeWq2Gbkw23+qBbz8dQ8a0qGawzUM82TbudzXoHHmN8Ta/AY07TVBmtx3K3vUO3iR5Y7KP=kjLNQE=KZDQ2zReNpqGiRaAgvKTLeAGi3zkiTZD5sfD+4e9MwdY6F3quTtqEY7p3Po++g8ooxni==rtalYh66pLHkq4/8qfODtAxrOQIi5=GW+xoh4QE4=I1=3bbS0dTFA2YhpQFLwmHKdcfWKfkOE2ch1x2Q1R5QzC8Ro2gpPQ1rF0=r5k73OBeDFrwm2QTCUhPD7j=AD=cX7DQOagvvGAMwcFeiQr4xc/6G4oL=nKNYC6wFRMYroZrDOKqI1YIf1+CQEm6I1K/Eqg7WHQbM4=VLYSG4fU+Xc2obI4xZ9+k7d0UYQKDGcDD2equfHeqz7KeNm4eeD=; sl-session=WBnXbN0aamccdlb8PI3IDw==; Hm_lvt_e23800c454aa573c0ccb16b52665ac26=1733810603,1734920543; HMACCOUNT=3905311843176655; PHPSESSID=ee1a81319c1138348744bc3aad19c1bd; SHARESESSID=ee1a81319c1138348744bc3aad19c1bd; Hm_lpvt_e23800c454aa573c0ccb16b52665ac26=1734929679; _ga_MJYFRXB3ZX=GS1.1.1734927152.8.1.1734929679.0.0.0',
    'pragma': 'no-cache',
    'priority': 'u=1, i',
    'referer': 'https://segmentfault.com/q/1010000045595831',
    'sec-ch-ua': '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'token': 'ee1a81319c1138348744bc3aad19c1bd',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',
}

params = {
    'keyv': '24.11.06',
    'ivd': 'CFQ+nSycin9TURJhA7d+m2N4A0rs0Rs7gcvJwiVFdn11Nr/3LHB+3CLtwHE6cGx2gnj9G77pPRD64xlFPeScchPBqi8sWUgKkg6aFK83I5snkHbej8Ml+wZM2j6AjaS30ac1wH2Ypeef/9MZCWd7WMvrTfv9PKBAVSelE9nMkMrvNS6bUpk6xppVUjndjRGyRbDYNkOwA9xqkK/u8ehaBN039ArR0mXjz9qmk0nEAoxoejBA+aVx62jMTNMLckihduFK2arRpzT7lcvIZfl1uvylt7lUheILdV8Rl4vKZT053HeMrFYt2+ksEwfD7YkXhc8UqnSmFOgWkSjULW+Flg==',
}


# '{"query":"current","timestamp":1734929715}'
dict={}
# query=params['query']
timestamp=str(int(time.time()))

# dict['query']=query
dict['timestamp']=timestamp
dd=json.dumps(dict)
print(dd)
sign = js_com.call('getIvd', dd)
print(sign)
params['ivd']=sign
response = requests.get(
    'https://segmentfault.com/gateway/question/1010000045595831/related',
    params=params,
    headers=headers,
)
print(response.status_code)
print(response.json())